
package com.kweative.model.relation;

import com.kweative.model.Index;
import com.kweative.model.Table;
import com.kweative.model.query.Select;
import com.kweative.model.query.WhereStatement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author henrik
 */
abstract public class Relation<P extends Table,C extends Table> implements Cloneable {
    private P parent = null;
    private C child = null;
    private Index index;

    public Relation(P parent) {
        this.parent = parent;
    }

    public Index getIndex() {
        return index;
    }

    public C getChild() {
        return child;
    }

    public P getParent() {
        return parent;
    }

    public void setChild(C child) {
        this.child = child;
        this.makeStructure();
    }
    abstract protected void makeStructure();

    public WhereStatement<Select,P> join(WhereStatement<Select,P> where) {
        return where;
    }

    @Override
    protected Relation<P,C> clone() {
        try {
            return (Relation<P,C>) super.clone();
        } catch (CloneNotSupportedException ex) {
            Logger.getLogger(Relation.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

}
